package base

import (
	"fmt"
	"sync"
)

func UseLock() {
	a := 0
	var mu sync.Mutex
	for i := 0; i < 5; i++{
		go func(index int) {
			mu.Lock()
			defer mu.Unlock()
			a += i
			fmt.Printf("goroutine: index %d, val %d\n", index, a)
		}(i)
	}
}

func UnuseLock() {
	a := 0
	for i := 0; i < 5; i++{
		go func(index int) {
			a += i
			fmt.Printf("goroutine: index %d, val %d\n", index, a)
		}(i)
	}
}